<?php

echo "Testing sha1_string...\n";

$failed = 0;

for ($i = 0; $i < 1024; $i++)
  {
    $hash = '';
    $str = md5(rand());
    exec("./sha1_string " . $str, $hash);
    if ($hash[0] !== sha1($str))
      {
	echo $hash[0] . " / " . sha1($str) . "\n";
	$failed++;
      }
  }

echo "Test done: " . ($i - $failed) . "/" . $i . "\n";

echo "Testing sha1_file...\n";

$failed = 0;

$dir = opendir("/bin");
$i = 0;
while (($item = readdir($dir)) !== false)
  {
    if ($item[0] != '.')
      {
	$i++;
	$hash = '';
	exec("./sha1_file /bin/" . $item, $hash);
	if ($hash[0] !== sha1_file("/bin/" . $item))
	  {
	    $failed++;
	  }
      }
  }

echo "Test done: " . ($i - $failed) . "/" . $i . "\n";

?>
